from math import sqrt
# 作业：
# 1.用类封装一个Math类, 实现加, 减, 乘, 除, 幂, 开方


class MyMath:
    def __init__(self):
        print("开始计算...")

    def addition(self, x, y):
        return x + y

    def subtraction(self, x, y):
        return x - y

    def multiplication(self, x, y):
        return x * y

    def division(self, x, y):
        return x / y

    def power(self, x, y):
        return x ** y

    def evolution(self, x):
        return sqrt(x)


# 2.自由课题, 按照自己的想法, 将身边的事物抽象成类, 并创建多个实例.
class NetworkEquipment:
    def __init__(self, name):
        self.name = name
        print("初始化该网络设备")

    def vendors(self, v):
        print(f"该网络设备的厂商是：{v}")


class SafetyEquipment:
    def __init__(self, name):
        self.name = name
        print("初始化该安全设备")

    def vendors(self, v):
        print(f"该安全设备的厂商是：{v}")


# 继承
class Router(NetworkEquipment):
    def __init__(self, name):
        self.name = name
        self.t = __class__.__name__
        super(Router, self).__init__(self.name)

    def vendors(self, v):
        print(f"该路由器的厂商是：{v}")

    def func(self):
        print(f"该设备的功能是路由")


# 多继承
class FireWall(NetworkEquipment, SafetyEquipment):
    def __init__(self, name):
        self.name = name
        self.t = __class__.__name__
        print("该设备既是网络设备，也是安全设备")
        super(FireWall, self).__init__(self.name)
        super(NetworkEquipment, self).__init__(self.name)

    def vendors(self, v):
        print(f"该防火墙厂商是：{v}")

    def func(self):
        print(f"该设备的功能是安全防护")


if __name__ == "__main__":
    my_math = MyMath()
    print(f"加法运算：{my_math.addition(1, 2)}")
    print(f"减法运算：{my_math.subtraction(3, 9)}")
    print(f"乘法运算：{my_math.multiplication(2, 8)}")
    print("除法运算：" + "{:.2f}".format(my_math.division(134, 9)))
    print(f"幂运算：{my_math.power(2, 3)}")
    print(f"开方运算：{my_math.evolution(64)}")
    print()
    # 创建实例
    my_device = NetworkEquipment("交换机")
    print(f"该设备是{my_device.name}")
    my_device.vendors("华为")
    print()
    device1 = Router("家用路由器")
    print(f"该设备是{device1.name}\n该设备类型是{device1.t}")
    device1.vendors("TP-Link")
    device1.func()
    print()
    device2 = FireWall("ASA")
    print(f"该设备是{device2.name}\n该设备类型是{device2.t}")
    device2.vendors("思科")
    device2.func()
